﻿<UserControl x:Class="StockholmsStad.Windows.UI.Modules.Minister.Controls.MinisterServiceListControl"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:converters="clr-namespace:StockholmsStad.Windows.UI.Infrastructure.Converters;assembly=StockholmsStad.Windows.UI.Infrastructure"
    xmlns:localconverters="clr-namespace:StockholmsStad.Windows.UI.Modules.Minister.Converters">
    <UserControl.Resources>
        <localconverters:MinisterTimeBlockToServiceString x:Key="ministerServiceConverter" />
        <converters:DateTimeToDateString x:Key="startDateTimeConverter" />
        <localconverters:MinisterTimeBlockToStartEndTimeString x:Key="ministerStartEndTimeConverter" />

        <CollectionViewSource x:Key="cvs" Source="{Binding MinisterServiceList, Path=MinisterServiceList.MinisterServiceTimeBlocks}">
            <CollectionViewSource.GroupDescriptions>
                <PropertyGroupDescription PropertyName="Month" />
            </CollectionViewSource.GroupDescriptions>
        </CollectionViewSource>

    </UserControl.Resources>

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>

        <ListView x:Name="listViewMonths" Grid.Row="0" BorderThickness="0" Width="250" Height="210" VerticalAlignment="Top" 
                  ScrollViewer.HorizontalScrollBarVisibility="Disabled" ScrollViewer.VerticalScrollBarVisibility="Auto" 
                  ItemsSource="{Binding Source={StaticResource cvs}}" ItemContainerStyle="{DynamicResource ListViewItemStyleNoInteraction}">
            <ListView.GroupStyle>
                <GroupStyle>
                    <GroupStyle.ContainerStyle>
                        <Style TargetType="{x:Type GroupItem}">
                            <Setter Property="Margin" Value="0,0,0,5"/>
                            <Setter Property="Template">
                                <Setter.Value>
                                    <ControlTemplate TargetType="{x:Type GroupItem}">
                                        <Expander IsExpanded="True" BorderBrush="#FFA4B97F" BorderThickness="0,0,0,0" Margin="0,0,0,5">
                                            <Expander.Header>
                                                <DockPanel>
                                                    <TextBlock FontWeight="Bold" Text="{Binding Path=Name}" />
                                                </DockPanel>
                                            </Expander.Header>
                                            <Expander.Content>
                                                <ItemsPresenter />
                                            </Expander.Content>
                                        </Expander>
                                    </ControlTemplate>
                                </Setter.Value>
                            </Setter>
                        </Style>
                    </GroupStyle.ContainerStyle>
                </GroupStyle>
            </ListView.GroupStyle>
            <ListView.View>
                <GridView x:Name="gridViewDays">
                    <GridView.ColumnHeaderContainerStyle>
                        <Style>
                            <Setter Property="FrameworkElement.Visibility" Value="Collapsed" />
                        </Style>
                    </GridView.ColumnHeaderContainerStyle>
                    <GridViewColumn DisplayMemberBinding="{Binding Path=TimeBlock.StartDateTime, Converter={StaticResource startDateTimeConverter}}" Width="75" />
                    <GridViewColumn DisplayMemberBinding="{Binding Path=TimeBlock, Converter={StaticResource ministerStartEndTimeConverter}}" Width="75" />
                    <GridViewColumn DisplayMemberBinding="{Binding Path=TimeBlock, Converter={StaticResource ministerServiceConverter}}" />
                </GridView>
            </ListView.View>

        </ListView>

    </Grid>
    
</UserControl>
